package site.jlopen.test;

import java.util.Map;

import site.jlopen.secret.client.SecretClientHttp;
import site.jlopen.secret.client.SecretClientHttpErrorCode;
import site.jlopen.secret.client.SecretReqUrl;
import site.jlopen.secret.common.SecretClientResponse;
import site.jlopen.secret.common.SecretReqBaseForm;
import site.jlopen.secret.config.SecretClientProperties;

public class ApiProp {
 
	public static SecretClientProperties getP() {
		SecretClientProperties clientProperties = new SecretClientProperties();
		clientProperties.setHost("http://192.168.0.234:8878");
		clientProperties.setAppId("carro");
		clientProperties.setAppSecret("123456");
		return clientProperties;
	}
	
	public static String login() {
		SecretClientHttp<String> clientRequest = new SecretClientHttp<String>(getP());
		Map<String, Object> form = new SecretReqBaseForm<Object>()
				.appId(getP().getAppId())
				.add("username", getP().getAppId())
				.add("password", getP().getAppSecret());
		SecretClientResponse<String>  res = clientRequest.execute(SecretReqUrl.AUTH_URL, form);
		if(res.getStatus() == SecretClientHttpErrorCode.SUCCESS) {
			return res.getData();
		}
		return null;
	}
}
